package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.model.LineFaultEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by ding on 2017/8/4.
 */
public interface RoadLineFaultRepository extends CrudRepository<LineFaultEntity, Long> {

    /**
     * @Description: 故障审核DT
     * @Author: jiang-weirong
     * @Date: 2017/8/4 11:13
     */
    public List<DTLineFaultDto> getRoadLineFaultCheck4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId) throws Exception;

    public Integer getRoadLineFaultCheckCount4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId) throws Exception;

    /**
     * @Description: 获取单位审核人审核状况
     * @Author: jiang-weirong
     * @Date: 2017/8/4 11:13
     */
    @Query(value = "select lf.roadLineCheck from LineFaultEntity lf where lf.roadLineFaultId = ?1")
    public Integer getLampCheck(Integer lampFaultId) throws Exception;

    /**
     * @Description: 主管审核通过
     * @Author: jiang-weirong
     * @Date: 2017/8/4 11:18
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  mf SET mf.roadLineMainCheck=?1, mf.roadLineMainCheckerId=?4,mf.roadLineFeedback=?2,mf.roadLineMaintenanceStatus=1,mf.roadLineMainCheckTime=?5 WHERE mf.roadLineFaultId=?3")
    public Integer faultAudit2Success(Integer isPass, String feedback, Integer lampFaultId, Integer userId, String dateNowStr) throws Exception;

    /**
     * @Description: 主管审核拒绝
     * @Author: jiang-weirong
     * @Date: 2017/8/4 11:20
     *
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  lf SET lf.roadLineMainCheck=?1, lf.roadLineMainCheckerId=?4,lf.roadLineFeedback=?2,lf.roadLineMainCheckTime=?5 WHERE lf.roadLineFaultId=?3")
    public Integer faultAudit2Fail(Integer isPass, String feedback, Integer monitorFaultId, Integer userId, String dateNowStr) throws Exception;

    /**
     * @Description: 单位审核人审核
     * @Author: jiang-weirong
     * @Date: 2017/8/4 11:22
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  lf SET lf.roadLineCheck= ?1,lf.roadLineCheckerId=?4,lf.roadLineFeedback=?2,lf.roadLineCheckTime=?5 WHERE lf.roadLineFaultId=?3")
    public Integer faultAudit(Integer isPass, String feedback, Integer monitorFaultId, Integer userId, String dateNowStr) throws Exception;
    
    /**
     * @Description: 
     * @Author: xu_jiaHui
     * @Date: 17-11-18 下午3:40
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  lf SET lf.roadLineCheck= ?1,lf.roadLineCheckerId=?4,lf.roadLineFeedback=?2,lf.roadLineCheckTime=?5,lf.roadLineMainCheck=?1,lf.roadLineMainCheckTime=?5,lf.roadLineMaintenanceStatus=1 WHERE lf.roadLineFaultId=?3")
    public Integer straightFaultAudit(Integer isPass, String feedback, Integer monitorFaultId, Integer userId, String dateNowStr) throws Exception;

    /**
     * @Description: 故障处理DT
     * @Author: jiang-weiron
     * @Date: 2017/8/4 13:23
     */
    public List<DTLineFaultDto> getRoadLineFaultHandle4DT(DTRequestDto dtRequestDto, String actorIds, Integer orgId, Integer maintenanceStatus) throws Exception ;

    public Integer getRoadLineFaultHandleCount4DT(DTRequestDto dtRequestDto, String actorIds, Integer orgId, Integer maintenanceStatus) throws Exception;

    /**
     * @Description: 添加施工方案
     * @Author: jiang-weirong
     * @Date: 2017/8/4 13:23
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  lf SET lf.roadLineMaintenanceContent = ?2 WHERE lf.roadLineFaultId =?1")
    public Integer addRoadLineMaintenanceContent(Integer monitorFaultId, String monitorMaintenanceContent) throws Exception;

    /**
     * @Description: 完成施工
     * @Author: jiang-weirong
     * @Date: 2017/8/4 13:24
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  lf SET lf.roadLineMaintenancePhoto = ?1,lf.roadLineMaintainerId=?2,lf.roadLineMaintenanceTime=?3,lf.roadLineMaintenanceExplain=?4,lf.roadLineMaintenanceStatus=2 WHERE lf.roadLineFaultId =?5")
    public Integer finishRoadLineMaintenance(String monitorMaintenancePhoto, Integer monitorMaintainerId, String monitorMaintenanceTime, String monitorMaintenanceExplain, Integer monitorFaultId) throws Exception;

    /**
     * @Description: 获取故障审核list4App
     * @Author: jiang-weirong
     * @Date: 2017/8/4 18:27
     */
    public List<LineFaultDto> getRoadLineFaultCheckList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size) throws Exception;

    /**
     * @Description: 故障详情
     * @Author: jiang-weirong
     * @Date: 2017/8/14 20:29
     */
    @Query(value = "select new com.hualude.roadsign.dto.LineFaultDto(lf.roadLineCheck,lf.roadLineMainCheck,lf.roadLineFeedback,lf.roadLineMoney," +
            "lf.roadLineFaultLevel,lf.roadLineFaultPhoto,lf.roadLineFaultType,lf.roadLineFaultReason,lf.roadLineFaultCreatorId, lf.roadLineFaultTime) " +
            "from LineFaultEntity lf where lf.roadLineFaultId=?1")
    public LineFaultDto getRoadLineFaultInfo2Fault(Integer roadLineFaultId) throws Exception;


    /**
     * @Description: 标线故障datatable
     * @Author: pan-jianan
     * @Date: 2017/8/5 12:16
     */
    public Integer getRoadLineReportFaultCount4DT(Integer actorId, Integer userId, Integer orgId, String strSearch) throws Exception;

    public List<DTLineFaultDto> getRoadLineReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) throws Exception;

    /**
     * @Description: 更新故障
     * @Author: pan-jianan
     * @Date: 2017/8/5 12:16
     */
    @Modifying
    @Query(value = "UPDATE LineFaultEntity  lf SET lf.roadLineFaultLevel = ?2,lf.roadLineFaultType = ?3,lf.roadLineFaultPhoto = ?4,lf.roadLineFaultReason = ?5,lf.roadLineMoney =?6 WHERE lf.roadLineFaultId =?1")
    public Integer updateRoadLineFault(Integer roadLineFaultId, Integer roadLineFaultLevel, Integer roadLineFaultType, String roadLineFaultPhoto, String roadLineFaultReason, Double roadLineMoney) throws Exception;

    /**
     * @Description: 删除故障
     * @Author: pan-jianan
     * @Date: 2017/8/5 12:16
     */
    @Modifying
    @Query(value = "delete from LineFaultEntity lf where lf.roadLineFaultId=?1")
    public Integer deleteRoadLineFaultByIds(Integer roadLineFaultId) throws Exception;

    /**
     * @Description: 删除标线故障
     * @author xu_jiaHui
     * @date 2017/8/17 13:00
     */
    @Modifying
    @Query(value = "delete from LineFaultEntity where roadLineId = ?1")
    public Integer deleteLineFault(Integer roadLineId) throws Exception;

    /**
     * @Description: 是否可上报
     * @Author: pan-jianan
     * @Date: 2017/8/5 17:50
     */
    @Query(value = "select new com.hualude.roadsign.dto.LineFaultDto(lf.roadLineCheck,lf.roadLineMainCheck,lf.roadLineMaintenanceStatus) " +
            "from LineFaultEntity lf where lf.roadLineId=?1  ORDER BY lf.roadLineFaultTime DESC ")
    public List<LineFaultDto> getRoadLineFaultIsReport(Integer roadLineId) throws Exception;


    /**
     * @Description: app获取标线故障维修列表
     * @Author: pan-jianan
     * @Date: 2017/8/5 19:27
     */
    public List<LineFaultDto> getRoadLineFaultHandleList4App(Integer orgId, Integer maintenanceStatus, String actorIds, Integer count, Integer size)throws Exception;

    /**
     * @Description: app 标线回执单
     * @Author: pan-jianan
     * @Date: 2017/8/5 19:27
     */
    @Query(value = "select new com.hualude.roadsign.dto.LineFaultDto(mf.roadLineId,mf.roadLineMainCheckTime, mf.roadLineFaultLevel," +
            "mf.roadLineFaultPhoto,mf.roadLineFaultType,mf.roadLineFaultReason,mf.roadLineMaintenancePhoto,mf.roadLineMaintenanceContent,mf.roadLineMaintenanceExplain," +
            "mf.roadLineMaintenanceTime,  m.roadLineProvince, m.roadLineCity," +
            " m.roadLineArea, m.roadLineRoadName,m.roadLineStartRoad,m.roadLineEndRoad,mf.roadLineFeedback)" +
            " from RoadLineEntity m,LineFaultEntity mf " +
            "WHERE m.roadLineId=mf.roadLineId AND mf.roadLineFaultId = ?1")
    public LineFaultDto getRoadLineReceiptInfo4App(Integer monitorFaultId) throws Exception;

    /**
     * @Description: 故障list4App
     * @Author: jiang-weirong
     * @Date: 2017/8/9 17:36
     */
    public List<LineFaultDto> getRoadLineFaultReportList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size) throws Exception;

    /**
     * @Description: 根据标线id获取坐标集
     * @Author: pan-jianan
     * @Date: 2017/8/25 14:32
     */
    public LineFaultDto getRoadLineLatLng(Integer roadLineId) throws Exception;

    /**
     * @Description: 获取推送相关信息
     * @Author: jiang-weirong
     * @Date: 2017/9/11 11:48
     */
    @Query(value = "select new com.hualude.roadsign.dto.LineFaultDto(roadLineId, roadLineOrgId, roadLineMainOrgId, roadLineFaultType) from LineFaultEntity where roadLineFaultId = ?1")
    public LineFaultDto getInfoByFaultId(Integer lampFaultId) throws Exception;
}
